package com.ruoyi.wechat.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.wechat.domain.WxWxMsg;
import com.ruoyi.wechat.mapper.WxWxMsgMapper;
import com.ruoyi.wechat.service.WxWxMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author 26233
 */
@Slf4j
@Service("wxWxMsgService")
public class WxWxMsgServiceImpl extends ServiceImpl<WxWxMsgMapper, WxWxMsg> implements WxWxMsgService {
    @Resource
    private WxWxMsgMapper wxWxMsgMapper;

    /**
     * 记录msg，异步入库
     *
     * @param msg
     */
    @Override
    @Async
    public void addWxMsg(WxWxMsg msg) {
        this.baseMapper.insert(msg);
    }

    /**
     * 查询
     *
     * @param wxWxMsgVo
     * @return
     */
    @Override
    public Page<WxWxMsg> selectWxMsgList(Page page, WxWxMsg wxWxMsgVo) {

        Page<WxWxMsg> msgVoPage = new Page<>(page.getCurrent(), page.getSize());
        return msgVoPage.setRecords(wxWxMsgMapper.selectWxMsgList(msgVoPage, wxWxMsgVo.getNickname(),
                wxWxMsgVo.getPhone(), wxWxMsgVo.getQrSceneStr(), wxWxMsgVo.getSubscribeScene(),
                wxWxMsgVo.getAppid(), wxWxMsgVo.getInOut(), wxWxMsgVo.getOpenid(),wxWxMsgVo.getMsgType()));
    }
//    @Override
//    public PageUtils queryPage(Map<String, Object> params) {
//        String msgTypes = (String)params.get("msgTypes");
//        String startTime = (String)params.get("startTime");
//        String openid = (String)params.get("openid");
//        String appid = (String) params.get("appid");
//        IPage<WxMsg> page = this.page(
//                new Query<WxMsg>().getPage(params),
//                new QueryWrapper<WxMsg>()
//                        .eq(StringUtils.hasText(appid), "appid", appid)
//                        .in(StringUtils.hasText(msgTypes),"msg_type", Arrays.asList(msgTypes.split(",")))
//                        .eq(StringUtils.hasText(openid),"openid",openid)
//                        .ge(StringUtils.hasText(startTime),"create_time",startTime)
//        );
//
//        return new PageUtils(page);
//    }


}
